<template>
  <render v-bind="props"></render>
</template>
<script setup lang="ts" name="opus-module-content">
import { h } from 'vue'
import { PARA_TYPE, ParagraphItem } from '../util'
import ParaType1 from '../paras/ParaType1.vue'
import Blockquote from '../paras/Blockquote.vue'
import Line from '../paras/Line.vue'
import List from '../paras/List.vue'
import Pic from '../paras/Pic.vue'
import LinkCard from '../paras/LinkCard.vue'
type PROPS = { data: { paragraphs: ParagraphItem[] } }
const props = withDefaults(defineProps<PROPS>(), {
  data: () => ({ paragraphs: [] }),
})
const render = (props: PROPS) => {
  return props.data.paragraphs.map((item) => {
    switch (item.para_type) {
      case PARA_TYPE.TEXT:
      case PARA_TYPE.HEADER1:
      case PARA_TYPE.HEADER2:
        return h(ParaType1, { data: item })
      case PARA_TYPE.BLOCKQUOTE:
        return h(Blockquote, { data: item })
      case PARA_TYPE.DIVIDER:
        return h(Line, { data: item })
      case PARA_TYPE.LIST:
        return h(List, { data: item })
      case PARA_TYPE.IMAGE:
        return h(Pic, { data: item })
      case PARA_TYPE.LINK_CARD:
        return h(LinkCard, { data: item })
      default:
        return h('div', {}, '无法显示')
    }
  })
}
</script>
<style lang="scss">
:root {
  --graph_bg_thick: #e3e5e7;
  --text_link: #00699d;
  --text1: #18191c;
  --text2: #61666d;
  --text3: #9499a0;
  --graph_bg_thin_rgb: 246, 247, 248;
  --brand_blue: #00aeec;
  --text_white: #ffffff;
  --line_regular: #e3e5e7;
  --bg1: #fff;
  --bg3: #f1f2f3;
}
.opus-module-content {
  color: #18191c;
  padding: 0;
  font-size: 17px;
  h1 {
    font-weight: bold;
    font-size: 20px;
    line-height: 34px;
    margin: 0;
    &:not(:first-child) {
      margin-top: 36px;
    }
  }
  h2 {
    font-weight: bold;
    font-size: 19px;
    line-height: 31px;
    margin: 0;
    &:not(:first-child) {
      margin-top: 36px;
    }
  }
  p {
    margin: 0;
    padding: 0;
    font-size: 17px;
    line-height: 29px;
    &:not(:first-child) {
      margin-top: 24px;
    }
  }
  h1,
  h2,
  p {
    white-space: pre-wrap;
    word-break: break-word;
  }
  blockquote {
    line-height: 1.7;
    color: var(--text2);
    margin: 24px 0 0;
    padding: 0 0 0 22px;
    position: relative;
    white-space: pre-wrap;
    &::before {
      background-color: var(--graph_bg_thick);
      border-radius: 4px;
      bottom: 6px;
      content: '';
      left: 2px;
      position: absolute;
      top: 6px;
      width: 2px;
    }
  }
  .opus-para-line {
    margin-top: 20px;
    text-align: center;
    img {
      max-width: 100%;
    }
  }
  ol,
  ul {
    margin-top: 12px;
    padding-left: 12px;
    li {
      list-style: none;
      padding-left: 23px;
      word-break: break-all;
      &::before {
        display: inline-block;
        margin-left: -23px;
        margin-right: 8px;
        text-align: center;
        white-space: nowrap;
        width: 15px;
      }
      &.level-1 {
        margin-left: 0;
      }
    }
  }
  ul li::before {
    content: '\2022';
  }
  @for $i from 1 through 9 {
    ol li.level-#{$i} {
      counter-increment: list-#{$i - 1};
      $reset-list: ();
      @for $j from $i through min($i + 8, 9) {
        $reset-list: append($reset-list, list-#{$j}, space);
      }
      counter-reset: $reset-list;
    }
  }
  ol li::before {
    content: counter(list-0, decimal) '. ';
  }
  ol li {
    .level-1,
    .level-4,
    .level-7 {
      &::before {
        content: counter(list-0, decimal) '. ';
      }
    }
  }
}
a {
  & :active,
  & :hover,
  & :link,
  & :visited,
  & {
    text-decoration: none;
  }
}
.opus-text-rich-hl {
  color: var(--text_link);
  cursor: pointer;
}
.opus-para-pic {
  display: flex;
  &:not(:first-child) {
    margin-top: 20px;
  }
  &.center {
    justify-content: center;
  }
}
.link-card-opus {
  align-items: center;
  background-color: rgba(var(--graph_bg_thin_rgb), 0.8);
  border-radius: 6px;
  box-sizing: border-box;
  cursor: pointer;
  display: flex;
  height: 80px;
  padding: 0 12px;
  &__detail {
    flex: 1;
    overflow: hidden;
    padding-left: 4px;
  }
  &__title {
    -webkit-line-clamp: 1;
  }
  &__subtitle {
    color: var(--text3);
    margin-top: 4px;
  }
  &__cover {
    flex-shrink: 0;
    height: 56px;
    margin-left: 12px;
    width: 74px;
    img {
      border-radius: 4px;
      height: 100%;
      width: 100%;
    }
  }
}
.bili-dyn-card-link-common {
  &__wrap {
    &,
    .reference & {
      background-color: rgba(var(--graph_bg_thin_rgb), 0.8);
    }
    border-radius: 6px;
    box-sizing: border-box;
    display: flex;
    height: 80px;
    padding: 8px;
    width: 100%;
  }
  &__cover {
    background-color: var(--bg1);
    background-position: 50%;
    background-repeat: no-repeat;
    background-size: cover;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
    height: 100%;
    overflow: hidden;
  }
  &__detail {
    box-sizing: border-box;
    cursor: pointer;
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    padding: 0 12px;
    &__title {
      color: var(--text1);
      font-size: 14px;
      line-height: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      transition: all 0.2s;
      white-space: nowrap;
    }
    &__desc {
      -webkit-line-clamp: 1;
      color: var(--text3);
      font-size: 12px;
      height: 17px;
      line-height: 17px;
      margin-top: 4px;
    }
  }
  &__action {
    align-items: center;
    display: flex;
    flex-shrink: 0;
    margin: 0 8px;
    button {
      align-items: center;
      background-color: var(--brand_blue);
      border: none;
      border-radius: 6px;
      box-sizing: border-box;
      color: var(--text_white);
      cursor: pointer;
      display: flex;
      font-size: 13px;
      height: 30px;
      justify-content: center;
      line-height: 1;
      outline: none;
      width: 72px;
    }
  }
}
.bili-ellipsis {
  -webkit-box-orient: vertical;
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.fs-medium {
  font-size: 15px;
  line-height: 25px;
}
.fs-small {
  font-size: 13px;
  line-height: 18px;
}
</style>
